/** \file
* \par Subversion URL:
* \$URL: http://planar-rendering.googlecode.com/svn/trunk/engine/src/iteratecontext.hpp $
* \version \$Rev: 76 $
* \date    \$Date: 2009-04-20 02:26:00 +0000 (Mon, 20 Apr 2009) $
*/

#pragma once

/// <summary>
/// A helper class to store and manipulate certain constants in the fractal
/// iteration.
/// </summary>
class IterateContext
{
public:
	/// <summary>The Z quaternion.</summary>
	double Z[4];
	/// <summary>The Z quaternion, elements squared.</summary>
	double Zsq[4];
	/// <summary>The S quaternion.</summary>
	double *S[4];

	/// <summary>
	/// Reset Z to the value of S.
	/// </summary>
	inline void Reset()
	{
		for (int i = 0; i < 4; i++) Z[i] = *S[i];
	}

	/// <summary>
	/// Set Zsq based on Z.
	/// </summary>
	inline void SetSquares()
	{
		for (int i = 0; i < 4; i++) Zsq[i] = Z[i]*Z[i];
	}

	/// <summary>
	/// Get the pseudo-modulus of Z, the sum of the squares of its elements.
	/// </summary>
	/// <returns>The pseudo-modulus of Z.</returns>
	inline double Modulus()
	{
		return Zsq[0] + Zsq[1] + Zsq[2] + Zsq[3];
	}

	/// <summary>Add S to Z.</summary>
	inline void Add()
	{
		for (int i = 0; i < 4; i++) Z[i] += *S[i];
	}
};
